/**
 * 同步远程仓库
 */
const { createOutputDir, cloneOrPull } = require("../utils/scriptUtil");
module.exports = async function (repoInfoList, output) {
  //判断output目录是否存在，不存在创建
  createOutputDir(output);

  let taskList = [];
  //不存在仓库则clone，存在则pull
  for (let repoInfo of repoInfoList) {
    taskList.push(cloneOrPull(repoInfo, output));
  }
  let taskResList = await Promise.allSettled(taskList);

  let countSuccess = 0;
  taskResList.forEach((item) => {
    if (item?.status === "fulfilled") {
      countSuccess++;
    }
  });
  console.log(
    `共计${taskList.length}个仓库，同步成功${countSuccess}个，失败${
      taskList.length - countSuccess
    }个`
  );
  return true;
};
